<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台登录-X-admin1.1</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
   	<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" th:href="@{/css/font.css}">
	<link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <script type="text/javascript" th:src="@{/js/reconnecting-websocket.min.js}"></script>
	<script type="text/javascript" th:src="@{/js/init-socket.js}"></script>

	<style type="text/css">
		.xbs768 {
		    display: block;
		    padding-top: 25px;
		}
	</style>
	
</head>
<body>
    <!-- 中部开始 -->
    <div class="wrapper">
        <!-- 右侧主体开始 -->
        <div class="page-content">
          <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form"  enctype="multipart/form-data">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label xbs768">请输入标题:</label>
                    <div class="layui-form-item" style="display: inline-block;">
						<div class="layui-input-inline">
							<input type="text" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
							<input type="hidden" name="uid" placeholder="请输入uid" autocomplete="off" class="layui-input">
						</div>
<!-- 						 value="${session.uid}" -->
					</div>
					<div style="margin-left: 80px;margin-bottom: 70px">
<!-- 						<div id="preview" style="float:left"> -->
<!-- 							<img id="imghead" width="100px" height="100px" class="logo-size" src='' /> -->
<!-- 						</div> -->
						<input id="filgo" style="margin-left: 70px; margin-top: 30px;" type="file" name="file" onchange="changeToop('filgo','imghead');" value="上传图片">
					</div>
					<div style="text-align: center;">
						<label class="layui-form-label xbs768">请输入内容:</label>
						<textarea placeholder="公告内容" class="layui-textarea" style="width: 400px;" name="content"></textarea>
					</div>
                </div>
                <div class="layui-form-item">
                    <label for="L_sign" class="layui-form-label">
                    </label>
                    <button class="layui-btn"  lay-filter="save" >
                        	发送
                    </button>
                </div>
                
              </form>   
            <!-- 右侧内容框架，更改从这里结束 -->
          </div>
        </div>
        <!-- 右侧主体结束 -->
    </div>
    <!-- 中部结束 -->
    
    <script th:inline="javascript">
    //百度统计可去掉
   /*  var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })(); */
    
    
    
    
//     $(function(){
    	
//     	$(".layui-btn").click(function(){
//     		var title = $("[name=title]").val();
//         	var content = $("[name=content]").val();
//         	var uid = $("[name=uid]").val();
        	
//         	$.ajax({
//         		url:[[@{/notice/addnotice}]],
//         		type:"post",
// 				data:{
// 					"title":title,
// 					"content":content,
// 					"uid":uid
// 				},
// 				dataType:"text",
// 				success:function(result){
// 					console.log(result);
// 					window.parent.$("#layui-layer-shade1").remove();
// 			    	window.parent.$("#layui-layer1").remove(); 
// 				},error:function(date){
// 					window.parent.$("#layui-layer-shade1").remove();
// 			    	window.parent.$("#layui-layer1").remove(); 
// 					console.log(date)
// 				}
				
        		
//         	});
        	
        	
        	
//     	});
    	
//     });
    
    
    
    	 
    $(function(){
    	
    	$(".layui-btn").click(function(){
    		var title = $("[name=title]").val();
        	var content = $("[name=content]").val();
        	var uid = $("[name=uid]").val();
        	var form = $("form")[0];
        	var formData=new FormData(form);
        	
        	$.ajax({
        		url:[[@{/notice/addnotice}]],
        		type:"post",
        		data:formData,
				dataType:"text",
				contentType:false,
				processData:false,
				success:function(result){
					var index = parent.layer.getFrameIndex(window.name);
		   		    parent.layer.close(index);
					window.parent.$("#layui-layer-shade1").remove();
			    	window.parent.$("#layui-layer1").remove(); 
				},error:function(date){
					var index = parent.layer.getFrameIndex(window.name);
		   		    parent.layer.close(index);
					window.parent.$("#layui-layer-shade1").remove();
			    	window.parent.$("#layui-layer1").remove(); 
				}
        	});

    	});
    	
    	var ws = new WebSocket("ws://localhost:8080/mywebsocket");
    	ws.onopen = function(){
    		console.log("连接成功!!");
    	}
    	ws.onerror = function(){
    		console.log("失败!!");
    	}

    	ws.onmessage = function(result){
    		console.log(result.data);
    		alert(result.data);
    	}
    	
    	
    	
//     	var socket;
// 		if(typeof(WebSocket) == "undefined") {
// 			alert("您的浏览器不支持WebSocket");
// 			return;
// 		}

// 		$("#btnConnection").click(function() {
// 			//实现化WebSocket对象，指定要连接的服务器地址与端口
// 			socket = new WebSocket("ws://localhost:8080/WebSocketServer/ws/张三");
// 			//打开事件
// 			socket.onopen = function() {
// 				alert("Socket 已打开");
// 				//socket.send("这是来自客户端的消息" + location.href + new Date());
// 			};
// 			//获得消息事件
// 			socket.onmessage = function(msg) {
// 				alert(msg.data);
// 			};
// 			//关闭事件
// 			socket.onclose = function() {
// 				alert("Socket已关闭");
// 			};
// 			//发生了错误事件
// 			socket.onerror = function() {
// 				alert("发生了错误");
// 			}
// 		});

// 		$("#btnSend").click(function() {
// 			socket.send("这是来自客户端的消息" + location.href + new Date());
// 		});

// 		$("#btnClose").click(function() {
// 			socket.close();
// 		});
    	
    	});
    
    </script>
    
    
<!--     <script language="javascript" type="text/javascript"> -->
<!--  	    var wsUri ="ws://echo.websocket.org/";  -->
<!--  	    var output;   -->
	    
<!-- 	    function init() {  -->
<!--  	        output = document.getElementById("output");  -->
<!-- 	        testWebSocket();  -->
<!--  	    }   -->
	 
<!--  	    function testWebSocket() {  -->
<!--  	        websocket = new WebSocket(wsUri);  -->
<!--  	        websocket.onopen = function(evt) {  -->
<!-- 	            onOpen(evt)  -->
<!-- 	        };  -->
<!-- 	        websocket.onclose = function(evt) {  -->
<!-- 	            onClose(evt)  -->
<!-- 	        };  -->
<!-- 	        websocket.onmessage = function(evt) {  -->
<!--           onMessage(evt)  -->
<!--         };  -->
<!--  	        websocket.onerror = function(evt) {  -->
<!--  	            onError(evt)  -->
<!-- 	        };  -->
<!-- 	    }   -->
	 
<!-- 	    function onOpen(evt) {  -->
<!-- 	        writeToScreen("CONNECTED");  -->
<!-- 	        doSend("WebSocket rocks");  -->
<!-- 	    }   -->
	 
<!-- 	    function onClose(evt) {  -->
<!--  	        writeToScreen("DISCONNECTED");  -->
<!-- 	    }   -->
	 
<!-- 	    function onMessage(evt) {  -->
<!--  	        writeToScreen('<span style="color: blue;">RESPONSE: '+ evt.data+'</span>');  -->
<!--  	        websocket.close();  -->
<!--  	    }   -->
	 
<!--  	    function onError(evt) {  -->
<!--          writeToScreen('<span style="color: red;">ERROR:</span> '+ evt.data);  -->
<!-- 	    }   -->
	 
<!--  	    function doSend(message) {  -->
<!--  	        writeToScreen("SENT: " + message);   -->
<!--  	        websocket.send(message);  -->
<!--  	    }   -->
	 
<!--  	    function writeToScreen(message) {  -->
<!--  	        var pre = document.createElement("p");  -->
<!--  	        pre.style.wordWrap = "break-word";  -->
<!--  	        pre.innerHTML = message;  -->
<!--          output.appendChild(pre);  -->
<!--  	    }   -->
	 
<!--  	    window.addEventListener("load", init, false);   -->
<!--     </script> -->
</body>
</html>